<template>
	<view class="collectPage">
		<view class="card" v-for="(item,index) in list" :key="index" @click="choose(item)">
			<image :src="fileServer+item.productImg" mode="widthFix" class="img"></image>
			<view class="text">
				<text class="tit">{{item.productName}}</text>
				<view class="dec">
					<view class="m">
						<text class="red">{{item.mll}}</text>
						<text class="bf">% </text>
						<text>毛利</text>
					</view>
					<view class="m">
						<text>零售</text>
						<text class="red">{{item.price}}</text>
					</view>
					<view class="m">
						<text>产地{{item.chandi}}</text>
					</view>
				</view>
			</view>
		</view>
		<u-empty v-if="status!='loading'&&list.length==0"
		        mode="data"
		        icon="http://cdn.uviewui.com/uview/empty/list.png"
		>
		</u-empty>
		<u-loadmore :status="status" v-else />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileServer: this.$fileServer,
				list:[],
				status:'loading',//loading / nomore
				pageIndex:1,
				total:0,
				companyId:'',
			};
		},
		onLoad(options) {
			this.companyId = options.companyId;
			this.getList();
		},
		methods: {
			getList(){
				this.status = 'loading';
				let pageIndex = this.pageIndex;
				this.$api.company.getProductList({pageIndex,companyId: this.companyId}).then(res => {
					uni.stopPullDownRefresh(); // 关闭下拉刷新 
					if(res.code==200){
						let list = res.rows;
						if(pageIndex==1){
							this.list = list
						}else{
							this.list = this.list.concat(list)
						}
						this.total = res.total;
						if(this.list.length<res.total){
							this.status = 'loadmore';
						}else{
							this.status = 'nomore';
						}
					}
				})
			},
			choose(item){
				const eventChannel = this.getOpenerEventChannel();
				eventChannel.emit('someEvent', item);
				uni.navigateBack()  
			},
		},
		//上拉加载
		onReachBottom() {
			if(this.status == 'nomore'){
				return false
			}
			this.pageIndex++;
			this.getList();
		},
		onPullDownRefresh () {
		  this.pageIndex = 1;
		  this.getList();
		},
	}
</script>

<style lang="scss" scoped>
	.collectPage {background-color: #F8F9FA;min-height: 100vh;padding: 18rpx 28rpx;
		.card{width: 100%;padding: 20rpx;margin-bottom: 24rpx;
			background: #FFFFFF;
			border-radius: 16rpx;display: flex;align-items: center;
			.img{width: 116rpx;height: 116rpx;border-radius: 5rpx;}
			.text{flex: 1;padding-left:20rpx;
				.tit{color: #333333;font-weight: bold;font-size: 28rpx;lien-height:26rpx}
				.dec{display: flex;align-items: center;margin-top: 26rpx;
					.m{margin-right: 24rpx;color: #333333;font-size: 22rpx;
						.red{color: #E83149;font-size: 28rpx;}
						.bf{font-size: 16rpx;color: #E83149}
					}
					
				}
			}
		}
	}
</style>